﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.DataAccess
{
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the ACS (American Community Survey) district data summary.
        /// </summary>
        /// <param name="iDistrictID">The idistrictID.</param>
        /// <param name="iRegionIDList">The iregionID list.</param>
        /// <param name="iSourceLayerIDList">The isourcelayerID list.</param>
        /// <param name="iDictionaryIDList">The idictionaryID list.</param>
        /// <returns>List of <see cref="ACSDistrictSummaryDataDTO"/></returns>
        public List<ACSDistrictSummaryDataDTO> GetACSDistrictDataSummary(int iDistrictID, string iRegionIDList, string iSourceLayerIDList, string iDictionaryIDList)
        {
            List<ACSDistrictSummaryDataDTO> itemList = new List<ACSDistrictSummaryDataDTO>();

            string storedProcedureName = "usp_tl10GetDistrictDataSummary10";

            using (SqlConnection db = Connect())
            {
                SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
                StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
                SqlParameter dataPartIDParm = StoredProcedureCommand.Parameters.AddWithValue("iDistrictID", iDistrictID);
                dataPartIDParm.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm2 = StoredProcedureCommand.Parameters.AddWithValue("iRegionIDList", iRegionIDList);
                dataPartIDParm2.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm3 = StoredProcedureCommand.Parameters.AddWithValue("iSourceLayerIDList", iSourceLayerIDList);
                dataPartIDParm3.Direction = ParameterDirection.Input;
                SqlParameter dataPartIDParm4 = StoredProcedureCommand.Parameters.AddWithValue("iDictionaryIDList", iDictionaryIDList);
                dataPartIDParm4.Direction = ParameterDirection.Input;

                db.Open();
                using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        itemList.Add(ACSDistrictSummaryDTODataContract.DataContract(rdr));
                    }
                }
            }

            //Database db = Connect();
            //DbCommand dbCommand = db.GetStoredProcCommand("usp_tl10GetDistrictDataSummary10");
            //db.AddInParameter(dbCommand, "iDistrictID", DbType.Int32, iDistrictID);
            //db.AddInParameter(dbCommand, "iRegionIDList", DbType.String, iRegionIDList);
            //db.AddInParameter(dbCommand, "iSourceLayerIDList", DbType.String, iSourceLayerIDList);
            //db.AddInParameter(dbCommand, "iDictionaryIDList", DbType.String, iDictionaryIDList);
            //dbCommand.CommandTimeout = 60000;
            //using (IDataReader rdr = db.ExecuteReader(dbCommand))
            //{
            //    while (rdr.Read())
            //    {
            //        itemList.Add(ACSDistrictSummaryDTODataContract.DataContract(rdr));
            //    }
            //}
            return itemList;
        }

    }
}
